package com.ruoyi.jpbi.controller.jianshe;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.jpbi.domain.jianshe.Actualreceipt;
import com.ruoyi.jpbi.domain.jianshe.Fomation;
import com.ruoyi.jpbi.domain.jianshe.Planreceipt;
import com.ruoyi.jpbi.service.ActualreceiptService;
import com.ruoyi.jpbi.service.FomationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Auto zh
 * date 2019/10/16
 * 实际回款
 */
@Controller
@RequestMapping("/jianshe/actualreceipt")
public class ActualreceiptController extends BaseController {
    @Autowired
    ActualreceiptService actualreceiptService;

    @Autowired
    FomationService fomationService;


    private String prefix = "jpbi/jianshe/actualreceipt";
    /**
     * 跳转分页页面
     */
    @GetMapping()
    public String user() {
        return prefix + "/actualreceipt";
    }

    /**
     * 获取实际回款数据
     *
     * @param actualreceipt 条件查询对象
     */
    @RequestMapping("/list")
    @ResponseBody
    public TableDataInfo getPlanreceiptList(Actualreceipt actualreceipt, ModelMap mmap) {
        startPage();
        List<Actualreceipt> actualreceipts = actualreceiptService.findAllByUser(actualreceipt);
        return getDataTable(actualreceipts);
    }

    /**
     * 新增
     */
    @GetMapping("/add")
    public String add(ModelMap mmap) {
        mmap.put("fomation", fomationService.findAllFomation(new Fomation()));
        return prefix + "/add";
    }
    /**
     * 新增计划产值
     *
     * @param actualreceipt
     * @return
     */
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult add(@Validated Actualreceipt actualreceipt) {
        return toAjax(actualreceiptService.insertActualreceipt(actualreceipt));
    }

    /**
     * 修改
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        mmap.put("actualreceipt", actualreceiptService.findAllById(id));
        mmap.put("fomation", fomationService.findAllFomation(new Fomation()));
        return prefix + "/edit";
    }

    /**
     * 修改实际回款
     *
     * @param actualreceipt
     * @return
     */
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult edit(@Validated Actualreceipt actualreceipt) {
        return toAjax(actualreceiptService.updateActualreceipt(actualreceipt));
    }

    /**
     *删除计划回款
     * @param ids
     * @return
     */
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(actualreceiptService.deleteActualreceiptByIds(ids));
    }
}
